var _n67;
var cc__decorate = __decorate;
Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2AudioManager = require("AudioManager");
var $2TaSdk = require("TaSdk");
var $2ADInterface = require("ADInterface");
var $2WeChatConstant = require("WeChatConstant");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_WeChatAD = _n67 = /* */function (_l$default2) {
  babel_inherits(n, _l$default2);
  var _super98 = babel_createSuper(n);
  function n() {
    var _this223;
    babel_classCallCheck(this, n);
    _this223 = _super98.apply(this, arguments);
    _this223.bannerAd = [null];
    _this223.bannerAd2 = [null, null, null];
    _this223.windowWidth = wx.getSystemInfoSync().windowWidth;
    _this223.windowHeight = wx.getSystemInfoSync().windowHeight;
    _this223.nativeStyle = [{
      left: _this223.windowWidth - 75,
      top: _this223.windowHeight / 5,
      fixed: false
    }, {
      left: 200,
      top: 0,
      fixed: false,
      width: 50
    }, {
      left: 70,
      top: _this223.windowHeight / 5,
      fixed: false,
      windth: 70
    }, {
      left: _this223.windowWidth - 100,
      top: _this223.windowHeight / 5,
      fixed: false,
      windth: 70
    }, {
      left: _this223.windowWidth / 2,
      top: _this223.windowHeight / 7,
      fixed: false,
      width: _this223.windowWidth / 3
    }, {
      left: 30,
      top: _this223.windowHeight / 2,
      fixed: false
    }, {
      left: 30,
      top: _this223.windowHeight / 7,
      fixed: false,
      width: _this223.windowWidth / 3
    }];
    _this223.js_code = "";
    _this223.bannerIndex = 0;
    _this223.isShowBanner = false;
    _this223.bannerHeight = 200;
    _this223.bannerWidth = 800;
    _this223.isShare = false;
    return _this223;
  }
  babel_createClass(n, [{
    key: "initAd",
    value: function initAd() {
      wx.onError(function (e) {
        console.log("err===", e);
      });
      console.log("init===12345");
      this.createBanner();
      this.WxShowAndHide();
      this.login();
      wx.getSetting({
        withSubscriptions: true,
        success(e) {
          "accept" == e.subscriptionsSetting.SYS_MSG_TYPE_INTERACTIVE && (_n67.isSubscribe = true);
        }
      });
      this.createVideo();
      this.createNative(6);
      this.createNative(5);
      this.createNative(4);
      this.createNative(3);
      this.createNative(2);
      this.createNative(1);
      this.createNative(0);
    }
  }, {
    key: "login",
    value: function login() {
      var e = this;
      wx.login({
        success(t) {
          if (t.code) {
            console.log("login code:" + t.code + "    " + JSON.stringify(t));
            e.js_code = t.code;
            e.getOpenID();
          } else {
            console.log("登录失败！" + t.errMsg);
          }
        }
      });
    }
  }, {
    key: "getOpenID",
    value: function getOpenID() {
      var e = {
        appId: $2WeChatConstant.default.appId,
        code: this.js_code
      };
      console.log("login====1");
      var t = new XMLHttpRequest();
      t.open("POST", "https://ga.gamejym.com/fcm/pay_wx/getOpenId", true);
      t.setRequestHeader("Content-Type", "application/json; charset=utf-8");
      var a = JSON.stringify(e);
      t.send(a);
      t.onload = function () {
        if (4 === t.readyState && t.status >= 200 && t.status < 300) {
          var _e128 = JSON.parse(t.responseText);
          console.log("respText==111", _e128);
          $2WeChatConstant.default.openID = _e128.openid;
          console.log("openid===", $2WeChatConstant.default.openID);
        } else {
          console.error("请求api失败!" + t.status);
        }
      };
    }
  }, {
    key: "createNativeBanner",
    value: function createNativeBanner() {
      var _this224 = this;
      var e = wx.getSystemInfoSync().windowWidth;
      var t = wx.getSystemInfoSync().windowHeight;
      var _loop9 = function _loop9(_a60) {
        _this224.bannerAd2[_a60] = wx.createBannerAd({
          adUnitId: "adunit-c07f909c914c84bc",
          adIntervals: 30,
          style: {
            left: 0,
            top: t,
            width: e
          }
        });
        _this224.bannerAd2[_a60].onError(function (e) {
          console.log("errMsg===banner" + e.errMsg);
          console.log("errCode===banner" + e.errCode);
          _this224.bannerAd2[_a60] = null;
        });
        _this224.bannerAd2[_a60].onResize(function (e) {
          _this224.bannerHeight = e.height;
          _this224.bannerAd2[_a60].style.top = e.height * (_a60 + 1);
        });
      };
      for (var _a60 = 0; _a60 < this.bannerAd2.length; _a60++) {
        _loop9(_a60);
      }
    }
  }, {
    key: "showNativeBanner",
    value: function showNativeBanner() {
      var _this225 = this;
      var _loop10 = function _loop10(_e129) {
        null == _this225.bannerAd2[_e129] && (_this225.bannerAd2[_e129] = wx.createBannerAd({
          adUnitId: "adunit-c07f909c914c84bc",
          adIntervals: 30,
          style: {
            left: 0,
            top: _this225.bannerHeight * (_e129 + 1),
            width: wx.getSystemInfoSync().windowWidth
          }
        }));
        _this225.bannerAd2[_e129] && _this225.bannerAd2[_e129].show().then().catch(function () {
          _this225.bannerAd2[_e129] = null;
        });
      };
      for (var _e129 = 0; _e129 < this.bannerAd2.length; _e129++) {
        _loop10(_e129);
      }
    }
  }, {
    key: "hideNativeBanner",
    value: function hideNativeBanner() {
      for (var _e130 = 0; _e130 < this.bannerAd2.length; _e130++) {
        this.bannerAd2[_e130] && this.bannerAd2[_e130].hide();
      }
    }
  }, {
    key: "cacheBanner",
    value: function cacheBanner(e) {
      var _this226 = this;
      if (!(e > this.bannerAd.length)) {
        this.bannerAd[e] && this.bannerAd[e].show().then(function () {
          console.log("success1", e);
          console.log("top", _this226.bannerAd[e].style.top);
        }).catch(function () {
          console.log("fail1", e);
        });
        setTimeout(function () {
          _this226.cacheBanner(e + 1);
        }, 1e3);
      }
    }
  }, {
    key: "createNative",
    value: function createNative(e) {
      var _this227 = this;
      this["customAd" + e] = wx.createCustomAd({
        adUnitId: $2WeChatConstant.default.POSID_NativeAD[e],
        adIntervals: 30,
        style: this.nativeStyle[e]
      });
      this["customAd" + e].onError(function (t) {
        _this227["customAd" + e] = null;
        console.log("wx原生创建失败 err:" + t);
      });
    }
  }, {
    key: "showNative",
    value: function showNative(e) {
      var _this228 = this;
      this.hideNative(e);
      if (($2WeChatConstant.default.showJuzhen || 4 != e) && ($2WeChatConstant.default.showIcon || 3 != e && 2 != e)) {
        if (null == this["customAd" + e]) {
          this.createNative(e);
          return void console.log("createType==", e);
        }
        console.log("type===", e);
        this["customAd" + e].show().then(function () {
          console.log("原生广告加载成功0");
        }).catch(function (t) {
          _this228["customAd" + e] = null;
          console.log("原生广告展示失败222:" + JSON.stringify(t));
        });
        4 === e && this.customAd6.show().then(function () {
          console.log("原生广告加载成功0");
        }).catch(function (e) {
          _this228.customAd6 = null;
          console.log("原生广告展示失败222:" + JSON.stringify(e));
        });
      }
    }
  }, {
    key: "hideNative",
    value: function hideNative(e) {
      console.log("type==", e);
      if (null == e) {
        for (var _t81 = 0; _t81 < this.nativeStyle.length; _t81++) {
          this["customAd" + _t81] && this["customAd" + _t81].hide();
        }
      } else {
        this["customAd" + e] && this["customAd" + e].hide();
      }
    }
  }, {
    key: "creatInsert",
    value: function creatInsert() {
      this.insertAd = wx.createInterstitialAd({
        adUnitId: $2WeChatConstant.default.POSID_InsertAD
      });
    }
  }, {
    key: "createVideo",
    value: function createVideo() {
      console.log("vedeo====");
      this.rewardVideoAd = wx.createRewardedVideoAd({
        adUnitId: "adunit-e6759f9e9e4e1508"
      });
    }
  }, {
    key: "createVideo1",
    value: function createVideo1() {
      console.log("vedeo====");
      this.rewardVideoAd1 = wx.createRewardedVideoAd({
        adUnitId: "adunit-07c93477afd3ca62"
      });
    }
  }, {
    key: "showToast",
    value: function showToast(e) {
      wx.showToast({
        title: e
      });
    }
  }, {
    key: "showInsert",
    value: function showInsert() {
      this.creatInsert();
      var e = this;
      this.insertAd.load().then(function () {
        e.insertAd.show();
        e.log("插屏广告加载完成，准备展示");
      }).catch(function (t) {
        e.log("插屏广告异常:" + JSON.stringify(t));
        e.insertAd && e.insertAd.destroy();
      });
      this.insertAd.onError(function (t) {
        e.log("插屏广告加载出错： " + JSON.stringify(t));
        e.insertAd && e.insertAd.destroy();
      });
      this.insertAd.onClose(function (t) {
        e.log("插屏广告关闭:" + t);
        e.insertAd && e.insertAd.destroy();
      });
    }
  }, {
    key: "showVideo",
    value: function showVideo(e, t, a) {
      var _this229 = this;
      if (null != this.rewardVideoAd && null != this.rewardVideoAd) {
        this.insertIntervalTime = new Date().getTime();
        cc.game.pause();
        this.rewardVideoAd.show().then(function () {
          console.log("广告显示成功");
        }).catch(function (e) {
          cc.game.resume();
          console.log("广告组件出现问题", e);
          _this229.rewardVideoAd.load().then(function () {
            console.log("手动加载成功");
            return _this229.rewardVideoAd.show();
          }).catch(function () {
            a && a();
            _this229.showToast("暂无广告");
          });
        });
        this.rewardVideoAd.offClose();
        this.rewardVideoAd.offError();
        this.rewardVideoAd.onError(function (e) {
          console.log("视频广告出错err===", e);
          a && a();
          _this229.rewardVideoAd = null;
          _this229.createVideo();
          cc.game.resume();
        });
        this.rewardVideoAd.onClose(function (a) {
          if (a && a.isEnded || undefined === a) {
            e && e();
            _this229.showToast("奖励领取成功");
            cc.game.resume();
          } else {
            _this229.showToast("播放中途退出");
            t && t();
            cc.game.resume();
          }
        });
        this.rewardVideoAd.load();
      } else {
        this.createVideo();
      }
    }
  }, {
    key: "showVideo1",
    value: function showVideo1(e, t, a) {
      var _this230 = this;
      if (null != this.rewardVideoAd1 && null != this.rewardVideoAd1) {
        this.insertIntervalTime = new Date().getTime();
        cc.game.pause();
        this.rewardVideoAd1.show().then(function () {
          console.log("广告显示成功");
        }).catch(function (e) {
          cc.game.resume();
          console.log("广告组件出现问题", e);
          _this230.rewardVideoAd1.load().then(function () {
            console.log("手动加载成功");
            return _this230.rewardVideoAd1.show();
          }).catch(function () {
            a && a();
            _this230.showToast("暂无广告");
          });
        });
        this.rewardVideoAd1.offClose();
        this.rewardVideoAd1.offError();
        this.rewardVideoAd1.onError(function (e) {
          console.log("视频广告出错err===", e);
          a && a();
          _this230.rewardVideoAd1 = null;
          _this230.createVideo1();
          cc.game.resume();
        });
        this.rewardVideoAd1.onClose(function (a) {
          if (a && a.isEnded || undefined === a) {
            e && e();
            _this230.showToast("奖励领取成功");
            cc.game.resume();
          } else {
            _this230.showToast("播放中途退出");
            t && t();
            cc.game.resume();
          }
        });
        this.rewardVideoAd1.load();
      } else {
        this.createVideo1();
      }
    }
  }, {
    key: "requestSubscribeSystemMessage",
    value: function requestSubscribeSystemMessage(e) {
      wx.requestSubscribeSystemMessage({
        msgTypeList: ["SYS_MSG_TYPE_INTERACTIVE", "SYS_MSG_TYPE_RANK"],
        success(t) {
          e.success();
        },
        fail(e) {
          console.log("errr====", e.errMsg, "code====", e.errCode);
        }
      });
    }
  }, {
    key: "onAddToFavorites",
    value: function onAddToFavorites() {
      console.log("收藏===");
      wx.onAddToFavorites(function () {
        return {
          title: "我都异世界日记",
          imageUrl: ""
        };
      });
    }
  }, {
    key: "showBanner",
    value: function showBanner() {
      console.log("index==1", this.bannerIndex);
      var e = this.bannerIndex;
      this.bannerIndex++;
      this.bannerIndex = this.bannerIndex % this.bannerAd.length;
      if (null != this.bannerAd[e] && null != this.bannerAd[e]) {
        this.bannerAd[e].style.top = wx.getSystemInfoSync().windowHeight - this.bannerHeight;
        this.bannerAd[e].style.left = (wx.getSystemInfoSync().windowWidth - this.bannerWidth) / 2;
        this.bannerAd[e].show().then(function () {
          $2TaSdk.default.instance.postEvent("bannerExposure", {
            adsid: $2WeChatConstant.default.POSID_BannerAD
          });
        }).catch(function (e) {
          console.log("showBanner err:" + e);
        });
      } else {
        this.createBannerSingle(e);
      }
    }
  }, {
    key: "createBannerSingle",
    value: function createBannerSingle(e) {
      var _this231 = this;
      var t = wx.getSystemInfoSync().windowWidth;
      var a = wx.getSystemInfoSync().windowHeight;
      this.bannerAd[e] = wx.createBannerAd({
        adUnitId: $2WeChatConstant.default.POSID_BannerAD[e % 3],
        adIntervals: 30,
        style: {
          left: 0,
          top: a - 1,
          width: t,
          height: 200
        }
      });
      this.bannerAd[e].onError(function (t) {
        _this231.bannerAd[e] = null;
        console.log("initBanner err:" + t);
      });
    }
  }, {
    key: "createBanner",
    value: function createBanner() {
      var _this232 = this;
      var e = wx.getSystemInfoSync().windowWidth;
      var t = wx.getSystemInfoSync().windowHeight;
      var _loop11 = function _loop11(_a61) {
        _this232.bannerAd[_a61] = wx.createBannerAd({
          adUnitId: $2WeChatConstant.default.POSID_BannerAD[_a61],
          adIntervals: 30,
          style: {
            left: e - 1,
            top: t - 1,
            width: e / 3
          }
        });
        _this232.bannerAd[_a61].onError(function (e) {
          console.log("errMsg===banner" + e.errMsg);
          console.log("errCode===banner" + e.errCode);
          _this232.bannerAd[_a61] = null;
        });
        _this232.bannerAd[_a61].onResize(function (e) {
          _this232.bannerHeight = e.height;
          _this232.bannerWidth = e.width;
        });
      };
      for (var _a61 = 0; _a61 < this.bannerAd.length; _a61++) {
        _loop11(_a61);
      }
      setTimeout(function () {
        _this232.cacheBanner(0);
      }, 8e3);
    }
  }, {
    key: "hideBanner",
    value: function hideBanner() {
      console.log("hidebanner");
      for (var _e131 = 0; _e131 < this.bannerAd.length; _e131++) {
        this.bannerAd[_e131] && this.bannerAd[_e131].hide();
      }
    }
  }, {
    key: "recorderStart",
    value: function recorderStart() {}
  }, {
    key: "recorderStop",
    value: function recorderStop() {}
  }, {
    key: "share",
    value: function share(e, t) {
      this.isShare = true;
      this.shareCallBack = e;
      this.shareFailBack = t;
      wx.shareAppMessage({
        title: $2WeChatConstant.default.shareText,
        imageUrl: $2WeChatConstant.default.shareImageUrl[0],
        imameUrlId: $2WeChatConstant.default.shareImageUrlId[0]
      });
    }
  }, {
    key: "WxShowAndHide",
    value: function WxShowAndHide() {
      var _this233 = this;
      wx.onShow(function () {
        console.log("in");
        cc.game.resume();
        $2AudioManager.default.instance.resumeBgm();
        if (_this233.isShare) {
          if (_this233.canShare()) {
            _this233.shareCallBack && _this233.shareCallBack();
            _this233.showToast("分享成功!");
          } else {
            _this233.showToast("分享失败!");
            _this233.shareFailBack && _this233.shareFailBack();
          }
        }
        _this233.isShare = false;
      });
      wx.onHide(function () {
        console.log("exit");
        cc.game.pause();
        _this233.isShare && (_this233.shareTime = new Date().getTime());
      });
    }
  }, {
    key: "canShare",
    value: function canShare() {
      return !(new Date().getTime() - this.shareTime < 3e3 || (this.shareTime = new Date().getTime(), 0));
    }
  }, {
    key: "addShortcut",
    value: function addShortcut() {}
  }, {
    key: "exitGame",
    value: function exitGame() {
      wx.exitMiniProgram();
    }
  }, {
    key: "log",
    value: function log(e) {
      console.log("WeChatAD:" + e);
    }
  }]);
  return n;
}($2ADInterface.default);
def_WeChatAD.isSubscribe = false;
def_WeChatAD = _n67 = cc__decorate([ccp_ccclass], def_WeChatAD);
exports.default = def_WeChatAD;